package Aula19;

public class SplayPlayImpl implements SplayPlay {

	private Splay splay;

	public String letrasSplay(String caracteres) {
		if (caracteres == null) {
			return null;
		}
		splay = new Splay();
		caracteres = caracteres.toUpperCase();
		for (int i = 0; i < caracteres.length(); i++) {
			if(caracteres.charAt(i) >= 'A' && caracteres.charAt(i) <= 'Z')
				splay.inserir(caracteres.charAt(i));
		}
		String[] numbers = splay.preOrdemStr().split(" ");
		String saida = "";
		for (int i = 0; i < numbers.length; i++) {
			if (i != 0) {
				saida += " ";
			}
			saida += (char) Integer.parseInt(numbers[i]);
		}
		return saida;
	}

	public String rotacoes(int[] numerosDaArvore, int elementoRotacionado) {
		if(numerosDaArvore == null){
			return null;
		}
		splay = new Splay();
		for (int i : numerosDaArvore) {
			if (i >= 0)
				splay.inserir(i);
		}
		return splay.search(elementoRotacionado);
	}

	public static void main(String[] args) {
		SplayPlay sp = new SplayPlayImpl();

		int[] numeros = { 2, 6, 4, 8, 3, 7, 9, 7 };
		System.out.println(sp.rotacoes(numeros, 3));

		String teste = "AdEb";
		System.out.println(sp.letrasSplay(teste));

	}

}
